Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming
Defining an object reference as a return type
User-defined functions and class methods can define classes as return types. Classes are always returned by value. However, a copy of the object reference is made, not the object itself. An object reference cannot be returned to or from a remote application server.
This is the syntax to define a class return type for a method:
This is the syntax to define a class return type for a user-defined function:
Element descriptions for these syntax diagrams follow:
CLASSThe
CLASSkeyword is required if type-name conflicts with an abbreviation for a built in Progress data type, such asINT(INTEGER). Otherwise, it can optionally be used to clarify the readability of the statement.type-nameThe type name of the class or interface being returned. For more information on type names, see the "Using the CLASS construct" section or the "Using the INTERFACE construct" section, respectively.
method-nameThe name of the method.
[parameter[ ,parameter] ... ]Any parameters that you define for the method or user-defined function. For more information on the syntax of
parameter, see the “Parameter definition syntax” reference entry in OpenEdge Development: Progress 4GL Reference .function-nameThe name of the user-defined function.
The following code fragment, from the sample class
acme.myObjs.CustObj, illustrates a method returning a class return type, in this case, to initialize an error object (acme.myObjs.Common.ErrorObjclass) for use by the current instance ofacme.myObjs.CustObj:
The
ErrorHandler( )method definition is defined in the immediate super class. This method instantiates theacme.myObjs.Common.ErrorObjclass and returns the object to the caller, as shown:
Progress treats a return from a class method the same as an assignment. That is, the compiler verifies that the object reference being returned by the method is consistent with the variable it is being assigned to. For more information on the compatibility rules for assigning object references, see the "Assigning object references" section.
Thus, the rules for assignment of the return from a method or user-defined function are the same as an
OUTPUTparameter from a method. (For more information, see the "Defining an object reference as a parameter" section). The caller of the method must define an object reference that is the same class as the return object, or a super class or interface of the returned object reference. As with parameters, if the caller has as its target variable an object reference to a super class or interface, the caller can only invoke those methods that are defined by the super class or interface. If the caller attempts to invoke a method that is not defined in the super class or interface, the compiler generates an error.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |